﻿@model StackExchange.Opserver.Data.SQL.SQLInstance
@{
    Layout = null;
    const int errorMinutesToGet = 30;
    var errors = Model.GetErrorLog(errorMinutesToGet);
    var data = errors.SafeData(true);
}
    <div class="summary-dashboard">
        <h3><a href="/sql/instance?node=@Model.Name">@Model.Name</a><span class="note">:</span> Errors last @errorMinutesToGet.Pluralize("minute")
            <span class="top-right-info">Updated @errors.ToPollSpan()</span>
        </h3>
        <div class="dashboard-description">You clicked on Errors/sec, which is query errors. The below is a list of SQL Server's recent error log entries, which may not show the query errors. <br />However, if you're looking to troubleshoot errors, you would want to see this list anyway just to check.</div>
    @if (data.Any())
    {
        <div>
            <table>
                <thead>
                    <tr>
                        <th>Date</th>
                        <th>Process</th>
                        <th>Message</th>
                    </tr>
                </thead>
                <tbody>
                    @for (int i = 0; i < data.Count; i++)
                    {
                        var e = data[i];
                        <tr>
                            <td style="white-space: nowrap;">@e.LogDate.ToRelativeTimeSpan()</td>
                            <td style="white-space: nowrap;">@e.ProcessInfo</td>
                            <td>@e.Text</td>
                        </tr>
                        if (i > 50 && data.Count > 100)
                        {
                            <tr class="total-row">
                                <td colspan="3" class="no-content">
                                    There are @(data.Count.ToComma()) errors in the last @errorMinutesToGet.Pluralize("minute"), showing the most recent 50.
                                </td>
                            </tr>
                            break;
                        }
                    }
                </tbody>
            </table>
        </div>
    }
    else
    {
        <div class="no-content">No errors available from the last @errorMinutesToGet.Pluralize("minute")</div>
    }
    </div>